package com.learn.mydruid.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.concurrent.TimeUnit;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @date 2019-09-26 0:25
 */
@RestController
// @Api(tags = "MyContrller",description = "用户测试模块")
public class MyContrller {
  @Autowired
  JdbcTemplate jdbcTemplate;

  // @Qualifier("dataSource")
  // @Autowired
  // DataSource dataSource;

  // @ApiOperation(value = "添加用户", notes = "根据参数添加用户")
  @GetMapping("/query")
  public  String get(){
    // System.out.println("-----------------------+"+dataSource.getClass().getName());
    for (int i = 0; i < 10; i++) {
      try {
        // TimeUnit.MILLISECONDS.sleep(300);
        // System.out.println(dataSource.getConnection().toString());
      } catch (Exception e) {
        e.printStackTrace();
      }
      System.out.println(jdbcTemplate.queryForList("SELECT * FROM `cms_prefrence_area` WHERE id="+i));
    }
    return "hello";
  }

 /* @GetMapping("/query2")
  public  String get2() throws Exception{
    System.out.println("-----------------------+"+dataSource.getClass().getName());
    for (int i = 0; i < 10; i++) {
      Connection connection = dataSource.getConnection();
      PreparedStatement prepareStatement = connection
          .prepareStatement("SELECT * FROM `cms_prefrence_area` WHERE id="+i);
      ResultSet resultSet = prepareStatement.executeQuery();
      while (resultSet.next()) {
        String cityName = resultSet.getString("name");
        System.out.println(cityName);
      }

      // System.out.println(jdbcTemplate.queryForList("SELECT * FROM `cms_prefrence_area` WHERE id="+i));
    }
    return "hello";
  }*/
}
